var scrollObj_sendFlowerRank=null;
$( document ).on( "pagecreate", "#sendFlowerRank", function( event ) {
	
	 
});
$( document ).on( "pageshow", "#sendFlowerRank", function( event ) {
	
	access_token=getQueryString("access_token");
	
	pageNo="1";
	pageSize="10";
	$("#wrapper_sendFlowerRank  #pullDown").hide();
	$("#wrapper_sendFlowerRank  #pullUp").hide();
	
	scrollObj_sendFlowerRank=scrollPlugLoadedOfReturn_new("wrapper_sendFlowerRank",
			function() {
				setTimeout(function () {
					if(pageNo >= totalPage)
						return;
					pageNo++;
					loadData_sendFlowerRank(false,scrollObj_sendFlowerRank);
				}, 1000);	
			},
			function() {
				setTimeout(function () {
					if(pageNo>1){
						pageNo--;
						loadData_sendFlowerRank(true,scrollObj_sendFlowerRank);
						if(pageNo==1){
							$("#wrapper_sendFlowerRank  #pullDown").hide();
						}
					}
				}, 1000);
			});
		
		
		setTimeout(function () { loadData_sendFlowerRank(true,scrollObj_sendFlowerRank); }, 100);
		
		$("#sendFlowerRank").on("swipeleft",function(){
			$.mobile.changePage(rootPath+"/jsp/weixin/progressRank.jsp?access_token="+access_token);
			scrollObj_progressRank.destroy();
		});
		$("#sendFlowerRank").bind("swiperight",function(){
			scrollObj_sendFlowerRank.destroy();
			 $.mobile.changePage(rootPath+"/jsp/weixin/redFlowerRank.jsp?access_token="+access_token
					 , {transition:"slide",reverse:true}, true, true);
		});
});

/**
 * 
 * @param isFresh 是否刷新
 * @param isFresh 是否初始列表
 */
function loadData_sendFlowerRank(isFresh,scrollObj){
	showLoading();
	$.ajax({
	  	url: rootPath+"/user/sendFlowerRank.do",
	  	type: "POST",
	  	dataType: "text",
		data: "access_token="+access_token+"&pageNo="+pageNo+"&pageSize="+pageSize,
	  	success: function( response ) {
	  		hideLoading();
	  		var data=$.parseJSON(response);
			if(data.state=="200"){
				totalPage=data.data.totalPage;
		  		var totalRow=data.data.totalRow;
		  		var arr=data.data.rows;
				var content = "";
				for (var i=0;i<arr.length;i++){
					var headerPic=rootPath+defaultHeadPic;
					if(arr[i].headImageUrl!=undefined && arr[i].headImageUrl!="")
						headerPic=arr[i].headImageUrl;
					var toPage=rootPath+"/jsp/weixin/otherPersonInfo.jsp?access_token="+access_token+"&empId="+arr[i].empId;
					var flowerUrl=flower_;
			  		flowerUrl=rootPath+flowerUrl;
			  		var bgPicClass="";
					if(arr[i].id==1)
						bgPicClass="first";
					else if(arr[i].id==2)
						bgPicClass="second";
					else if(arr[i].id==3)
						bgPicClass="thirdly";
					else
						bgPicClass="";
					
					content +='<li>\
					  <a href="#"  onClick="goTo(\''+toPage+'\')">\
					  	<span class="ui-li-desc li_one '+bgPicClass+' ">'+(arr[i].id)+'</span>\
					  	<span class="ui-li-desc li_two "><img src="'+headerPic+'"  width="40" height="40"></span>\
						<span class="ui-li-desc li_three " >'+(arr[i].emp_name)+'</span>\
						<span class="ui-li-desc li_four " ><img src="'+flowerUrl+'" width="40" height="40"/></span>\
						<span class="ui-li-desc li_five " ><strong>'+parseInt(arr[i].sendFlowerNum)+'</strong></span>\
					  </a>\
					</li>';
				}
				if(arr.length<pageSize){
					$("#wrapper_sendFlowerRank  #pullUp").hide();
				}else{
					$("#wrapper_sendFlowerRank  #pullUp").show();
				}
				if(isFresh)
					$("#thelist_sendFlowerRank").html("");
				
				//页数是2的倍数时，清空缓存列表
				if(pageNo%3==0){
					$("#wrapper_sendFlowerRank  #pullDown").show();
					$("#thelist_sendFlowerRank").html("");
					$("#thelist_sendFlowerRank").append(content).listview('refresh');
				}else{
					$("#thelist_sendFlowerRank").append(content).listview('refresh');
				}
				scrollObj.refresh();
			}else{
				alert_wx('fail',data.msg);
			}
	  	}
	});
}
